package org.groupg.practice.javalin;

import io.javalin.Javalin;
import org.eclipse.jetty.proxy.AsyncProxyServlet;
import org.eclipse.jetty.servlet.ServletHolder;

public class ProxyPractice {
    public static void main(String[] args) {
        // Add org.eclipse.jetty:jetty-proxy to maven/gradle dependencies (e.g Javalin 5.3.2 uses Jetty 11.0.13)
        Javalin.create(config -> {
            config.jetty.modifyServletContextHandler(handler -> {
                ServletHolder proxyServlet = new ServletHolder(AsyncProxyServlet.Transparent.class); // JDK 8 类似这种写法
                proxyServlet.setInitParameter("proxyTo", "https://javalin.io/"); // 代理目标位置
                proxyServlet.setInitParameter("prefix", "/proxy");// 本机服务
                handler.addServlet(proxyServlet, "/proxy/*");
            });
        }).start(7000);
    }
}
